/*
*  Licensed Materials - Property of IBM
*  5725-G92 (C) Copyright IBM Corp. 2006, 2013. All Rights Reserved.
*  US Government Users Restricted Rights - Use, duplication or
*  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
var adapterAuthRealmChallengeHandler = WL.Client.createChallengeHandler("PushAppRealm");
//alert("auth");
adapterAuthRealmChallengeHandler.isCustomResponse = function(response) {
//	alert("adapterAuthRealmChallengeHandler.isCustomResponse");
	if (!response || !response.responseJSON	|| response.responseText === null) {
		//alert("false1");
		return false;
	}
	if (typeof(response.responseJSON.authRequired) !== 'undefined'){
		//alert("true");
		return true;
	} else {
		//alert("false2");
		return false;
	}
};

adapterAuthRealmChallengeHandler.handleChallenge = function(response){
	//alert("adapterAuthRealmChallengeHandler.handleChallenge");
	var authRequired = response.responseJSON.authRequired;

	if (authRequired == true){
//		$("#AppDiv").hide();
//		$("#AuthDiv").show();
//		$("#AuthPassword").empty();
//		$("#AuthInfo").empty();
//
//		if (response.responseJSON.errorMessage)
//	    	$("#AuthInfo").html(new Date() + " :: " + response.responseJSON.errorMessage);
	  // alert("start auth");
		var username = $('#phone').val();
		var password = "worklight";
       // alert(username);
		var invocationData = {
			adapter : "stAdp",
			procedure : "submitAuthentication",
			parameters : [ username]
		};

		adapterAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData, {});
	} else if (authRequired == false){
//		$("#AppDiv").show();
//		$("#AuthDiv").hide();
		//alert("auth success");
		adapterAuthRealmChallengeHandler.submitSuccess();
	}
};
